import plugins from './build/plugins'
import inputs from './build/input'
import outputs from './build/output'
import pkg from './package.json'
const isDev = process.env.NODE_ENV === 'development'
const isVue = process.env.NODE_TYPE === 'vue'

const generateOutput = (isVue, item) => {
  const formats = ['umd']
  let output = []
  const fold = isVue ? 'vue' : 'common'
  const isEntry = pkg.name === item.name
  formats.forEach((format) => {
    output.push({
      file: isEntry ? `libs/${fold}/index.min.js` : `${item.fold}/dist/${fold}/${item.name}.${format}.js`,
      name: item.name,
      format
    })
  })
  return output
}

export default () => {
  let config = []
  inputs.forEach((entry) => {
    const output = isDev ? outputs : generateOutput(isVue, entry)
    config.push({
      input: entry.path,
      output,
      plugins
    })
  })
  return config
}